package com.czwj.action;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.czwj.annotation.SystemControllerLog;
import com.czwj.entities.OperateResult;
import com.czwj.entities.UserInfo;
import com.czwj.entities.WarningValue;
import com.czwj.service.WarningValueService;

@Controller
public class WarningValueAction {
	@Resource
	WarningValueService warningValueService;
	
	@RequestMapping(value = "/warningvalue", method = RequestMethod.GET)
	@ResponseBody
	public List<WarningValue> warningValue(){
		Map<String, Object> map = new HashMap<String, Object>();
		Subject currentUser = SecurityUtils.getSubject();
		UserInfo userInfo = (UserInfo)currentUser.getSession().getAttribute("userInfo");
		map.put("companyid",userInfo.getCompanyid());
		List<WarningValue> list = warningValueService.search(map);
		return list;
	}
	
	@SystemControllerLog(description = "修改警报值")
	@RequestMapping(value = "/warningValueSave.do", method = RequestMethod.POST)
	@ResponseBody
	public OperateResult warningValueSave(@RequestBody WarningValue warningValue) throws Exception {
		OperateResult result = new OperateResult();
		Subject currentUser = SecurityUtils.getSubject();
		UserInfo userInfo = (UserInfo)currentUser.getSession().getAttribute("userInfo");
		warningValue.setCompanyid(userInfo.getCompanyid());
		int count  = warningValueService.updateByPrimaryKeySelective(warningValue);
		result.setSuccess(count > 0);
		return result;
	}
	
}